/* 
 * File:   Client.h
 * Author: faraj
 *
 * Created on September 26, 2009, 7:21 AM
 */

#ifndef _CLIENT_H
#define	_CLIENT_H

#include "../CTools/CTools.h"
#include "File.h"
#include "NOTIFICATION.h"


class Client
{
private:
    CSocket *sock;
    pthread_t *tid;
    
public:
    Client(CSocket* socket)
    {
        this->sock = socket;
        this->tid = new pthread_t();
    }

    bool close()
    {
        return sock->closeSocket();
    }
    
    bool close(string msg)
    {
        sock->writeln(msg);
        sock->writeln(NOTIFY_QUIT);
        return sock->closeSocket();
    }
    
    CSocket* getSocket()
    {
        return sock;
    }
    
    bool sendText(string text)
    {
        this->sock->writeln(text);
    }

    pthread_t* getThreadID()
    {
        return tid;
    }
    
    int getFD()
    {
        return sock->getSockfd();
    }
    
    string* getText()
    {
        return this->sock->readln();
    }

    bool sendFile(File *file)
    {
        return this->sock->sendFile(file->getPath());
    }
    
    File* getFile(string filename, int size)
    {
        CFile *cf = this->sock->getFile(filename, size);
        if(cf != NULL)
        {
            return new File(cf);
        }
        else
        {
            return NULL;
        }
    }
    
    CInetAddress* getAddress()
    {
        return sock->getAddress();
    }
};

#endif	/* _CLIENT_H */

